package com.james.wee.shuangseqiu.dadang;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.james.wee.shuangseqiu.bo.IDBBo;
import com.james.wee.shuangseqiu.bo.OpenNumber;
import com.james.wee.shuangseqiu.db.DB;

public class DaDang {

	public DaDang() {

	}

	public static List<DaBO> countDaBo(int c) throws Exception {
		List<IDBBo> list = null;
		String index = null;
		OpenNumber on = null;
		List<DaBO> daList = new ArrayList<DaBO>();
		for (int i = 1; i < (28+c); i++) {
		System.out.println("开始查询核计－－－"+i);
			if (i < 10)
				index = "0" + i;
			else
				index = "" + i;
			list = DB.getInstance().queryBoList(
					"select * from OpenNumber where opennum>'2012000' and  n_"+c+"='" + index + "'",
					OpenNumber.class);
			System.out.println("查询的结果集大小："+list.size());
			int len = list.size();
			if(len==0)
				continue;
			DaBO bo = new DaBO(index,len);
			for (int j = 0; j < len; j++) {
				on = (OpenNumber) list.get(j);
				if(c!=1)
				bo.add(on.getN_1());
				if(c!=2)
				bo.add(on.getN_2());
				if(c!=3)
				bo.add(on.getN_3());
				if(c!=4)
				bo.add(on.getN_4());
				if(c!=5)
				bo.add(on.getN_5());
				if(c!=6)
				bo.add(on.getN_6());
			}
			daList.add(bo);
		}
		return daList;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		java.io.BufferedWriter bw = null;
		try {
			for(int i=1;i<7;i++){
			List<DaBO> dalist = DaDang.countDaBo(i);
			File file = new File("/home/james/RedCount2012_0"+i+".csv");
			if(file.exists())
				file.delete();
			bw = new BufferedWriter(new FileWriter(file, true));
			for (DaBO db : dalist){
				bw.write(db.toString());
			}
			bw.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
		}
	}

}
